using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using ObjectLib;
using FftLib;
using StaticUtility;
using BmgNet;

namespace ObjectParser
{
	/// <summary>
	/// Summary description for FormLogGabor.
	/// </summary>
	public class FormLogGabor : System.Windows.Forms.Form
	{
		#region Form Variable Declarations
		private System.Windows.Forms.ListBox listColorDim;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.CheckBox checkDisplay;
		private System.Windows.Forms.CheckBox checkFreq;
		private System.Windows.Forms.CheckBox checkOrientation;
		private System.Windows.Forms.GroupBox groupFreq;
		private System.Windows.Forms.TextBox textCenterFreq;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textWidthFreq;
		private System.Windows.Forms.GroupBox groupOrientation;
		private System.Windows.Forms.TextBox textCenterOrientation;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox textWidthOrientation;
		private System.Windows.Forms.Button butRefresh;
		private System.Windows.Forms.TextBox textGamma;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.TextBox textCalculus;
		private System.Windows.Forms.CheckBox checkBidirectional;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem mSaveAs;
		private System.Windows.Forms.SaveFileDialog Sfd;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Panel panelLeft;
		private System.Windows.Forms.Panel panelMovie;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.CheckedListBox clbFrames;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.Button bRender;
		private System.Windows.Forms.Button bAdd;
		private System.Windows.Forms.Button bRemove;
		private System.Windows.Forms.TextBox textNtween;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Button bMovieDirectory;
		private System.Windows.Forms.Button butMoveUp;
		private System.Windows.Forms.Button butMoveDown;
		private System.Windows.Forms.FolderBrowserDialog Dsd;
		private System.Windows.Forms.TextBox textMoviename;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox textMovieWidth;
		private System.Windows.Forms.TextBox textMovieHeight;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.CheckBox checkAdaptWhite;
		private System.Windows.Forms.TextBox textWhiteFac;
		private System.Windows.Forms.Label labelCalculus;
		#endregion
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.listColorDim = new System.Windows.Forms.ListBox();
			this.label1 = new System.Windows.Forms.Label();
			this.checkDisplay = new System.Windows.Forms.CheckBox();
			this.checkFreq = new System.Windows.Forms.CheckBox();
			this.checkOrientation = new System.Windows.Forms.CheckBox();
			this.groupFreq = new System.Windows.Forms.GroupBox();
			this.textCenterFreq = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.textWidthFreq = new System.Windows.Forms.TextBox();
			this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
			this.textCenterOrientation = new System.Windows.Forms.TextBox();
			this.textWidthOrientation = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.checkAdaptWhite = new System.Windows.Forms.CheckBox();
			this.labelCalculus = new System.Windows.Forms.Label();
			this.checkBidirectional = new System.Windows.Forms.CheckBox();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.textNtween = new System.Windows.Forms.TextBox();
			this.textGamma = new System.Windows.Forms.TextBox();
			this.label11 = new System.Windows.Forms.Label();
			this.textWhiteFac = new System.Windows.Forms.TextBox();
			this.textMovieWidth = new System.Windows.Forms.TextBox();
			this.textMovieHeight = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.groupOrientation = new System.Windows.Forms.GroupBox();
			this.butRefresh = new System.Windows.Forms.Button();
			this.textCalculus = new System.Windows.Forms.TextBox();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.mSaveAs = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.Sfd = new System.Windows.Forms.SaveFileDialog();
			this.panelLeft = new System.Windows.Forms.Panel();
			this.panelMovie = new System.Windows.Forms.Panel();
			this.butMoveUp = new System.Windows.Forms.Button();
			this.bMovieDirectory = new System.Windows.Forms.Button();
			this.textMoviename = new System.Windows.Forms.TextBox();
			this.bRemove = new System.Windows.Forms.Button();
			this.bAdd = new System.Windows.Forms.Button();
			this.bRender = new System.Windows.Forms.Button();
			this.clbFrames = new System.Windows.Forms.CheckedListBox();
			this.label8 = new System.Windows.Forms.Label();
			this.butMoveDown = new System.Windows.Forms.Button();
			this.Dsd = new System.Windows.Forms.FolderBrowserDialog();
			this.groupFreq.SuspendLayout();
			this.groupOrientation.SuspendLayout();
			this.panelLeft.SuspendLayout();
			this.panelMovie.SuspendLayout();
			this.SuspendLayout();
			// 
			// listColorDim
			// 
			this.listColorDim.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.listColorDim.Location = new System.Drawing.Point(2, 20);
			this.listColorDim.Name = "listColorDim";
			this.listColorDim.Size = new System.Drawing.Size(126, 54);
			this.listColorDim.TabIndex = 0;
			this.listColorDim.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.listColorDim.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(2, 2);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(128, 16);
			this.label1.TabIndex = 1;
			this.label1.Text = "Color Channel";
			this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			this.label1.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.label1.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// checkDisplay
			// 
			this.checkDisplay.Checked = true;
			this.checkDisplay.CheckState = System.Windows.Forms.CheckState.Checked;
			this.checkDisplay.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkDisplay.Location = new System.Drawing.Point(4, 304);
			this.checkDisplay.Name = "checkDisplay";
			this.checkDisplay.Size = new System.Drawing.Size(124, 18);
			this.checkDisplay.TabIndex = 2;
			this.checkDisplay.Text = "Display";
			this.toolTip1.SetToolTip(this.checkDisplay, "Check to display the output in the Object Parser window.");
			this.checkDisplay.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.checkDisplay.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.checkDisplay.CheckedChanged += new System.EventHandler(this.checkDisplay_CheckedChanged);
			// 
			// checkFreq
			// 
			this.checkFreq.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkFreq.Location = new System.Drawing.Point(2, 80);
			this.checkFreq.Name = "checkFreq";
			this.checkFreq.Size = new System.Drawing.Size(128, 18);
			this.checkFreq.TabIndex = 3;
			this.checkFreq.Text = "Constrain frequency";
			this.checkFreq.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.checkFreq.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.checkFreq.CheckedChanged += new System.EventHandler(this.checkFreq_CheckedChanged);
			// 
			// checkOrientation
			// 
			this.checkOrientation.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkOrientation.Location = new System.Drawing.Point(2, 172);
			this.checkOrientation.Name = "checkOrientation";
			this.checkOrientation.Size = new System.Drawing.Size(128, 20);
			this.checkOrientation.TabIndex = 4;
			this.checkOrientation.Text = "Constrain orientation";
			this.checkOrientation.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.checkOrientation.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.checkOrientation.CheckedChanged += new System.EventHandler(this.checkOrientation_CheckedChanged);
			// 
			// groupFreq
			// 
			this.groupFreq.Controls.Add(this.textCenterFreq);
			this.groupFreq.Controls.Add(this.label2);
			this.groupFreq.Controls.Add(this.label3);
			this.groupFreq.Controls.Add(this.textWidthFreq);
			this.groupFreq.Location = new System.Drawing.Point(2, 102);
			this.groupFreq.Name = "groupFreq";
			this.groupFreq.Size = new System.Drawing.Size(128, 66);
			this.groupFreq.TabIndex = 5;
			this.groupFreq.TabStop = false;
			this.groupFreq.Text = "Frequency";
			this.groupFreq.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.groupFreq.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// textCenterFreq
			// 
			this.textCenterFreq.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textCenterFreq.Location = new System.Drawing.Point(56, 16);
			this.textCenterFreq.Name = "textCenterFreq";
			this.textCenterFreq.Size = new System.Drawing.Size(64, 20);
			this.textCenterFreq.TabIndex = 6;
			this.textCenterFreq.Text = "500";
			this.textCenterFreq.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textCenterFreq, "The center frequency is a positive number that determines the center of frequency" +
				" tuning for the log-gabor function.");
			this.textCenterFreq.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.textCenterFreq.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 16);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 23);
			this.label2.TabIndex = 6;
			this.label2.Text = "Center";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label2, "The center frequency is a positive number that determines the center of frequency" +
				" tuning for the log-gabor function.");
			this.label2.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.label2.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 40);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(40, 23);
			this.label3.TabIndex = 7;
			this.label3.Text = "Width";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label3, "The width of frequency, roughly equivalent to the number of orders of magnitude o" +
				"ver which the log-gabor function should be spread.");
			this.label3.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.label3.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// textWidthFreq
			// 
			this.textWidthFreq.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textWidthFreq.Location = new System.Drawing.Point(56, 40);
			this.textWidthFreq.Name = "textWidthFreq";
			this.textWidthFreq.Size = new System.Drawing.Size(64, 20);
			this.textWidthFreq.TabIndex = 8;
			this.textWidthFreq.Text = "2";
			this.textWidthFreq.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textWidthFreq, "The width of frequency, roughly equivalent to the number of orders of magnitude o" +
				"ver which the log-gabor function should be spread.");
			this.textWidthFreq.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.textWidthFreq.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			// 
			// toolTip1
			// 
			this.toolTip1.AutoPopDelay = 10000;
			this.toolTip1.InitialDelay = 500;
			this.toolTip1.ReshowDelay = 100;
			// 
			// textCenterOrientation
			// 
			this.textCenterOrientation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textCenterOrientation.Location = new System.Drawing.Point(56, 16);
			this.textCenterOrientation.Name = "textCenterOrientation";
			this.textCenterOrientation.Size = new System.Drawing.Size(48, 20);
			this.textCenterOrientation.TabIndex = 6;
			this.textCenterOrientation.Text = "0";
			this.textCenterOrientation.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textCenterOrientation, "The mean of orientation tuning (in radians).");
			this.textCenterOrientation.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.textCenterOrientation.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			// 
			// textWidthOrientation
			// 
			this.textWidthOrientation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textWidthOrientation.Location = new System.Drawing.Point(56, 40);
			this.textWidthOrientation.Name = "textWidthOrientation";
			this.textWidthOrientation.Size = new System.Drawing.Size(48, 20);
			this.textWidthOrientation.TabIndex = 8;
			this.textWidthOrientation.Text = "0.1";
			this.textWidthOrientation.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textWidthOrientation, "The standard deviation of orientation tuning (in radians).");
			this.textWidthOrientation.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.textWidthOrientation.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 16);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(40, 23);
			this.label4.TabIndex = 6;
			this.label4.Text = "Center";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label4, "The mean of orientation tuning (in radians).");
			this.label4.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.label4.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 40);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(40, 23);
			this.label5.TabIndex = 7;
			this.label5.Text = "Width";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label5, "The standard deviation of orientation tuning (in radians).");
			this.label5.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.label5.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// checkAdaptWhite
			// 
			this.checkAdaptWhite.Checked = true;
			this.checkAdaptWhite.CheckState = System.Windows.Forms.CheckState.Checked;
			this.checkAdaptWhite.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkAdaptWhite.Location = new System.Drawing.Point(4, 348);
			this.checkAdaptWhite.Name = "checkAdaptWhite";
			this.checkAdaptWhite.Size = new System.Drawing.Size(88, 18);
			this.checkAdaptWhite.TabIndex = 10;
			this.checkAdaptWhite.Text = "Adapt White";
			this.checkAdaptWhite.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.checkAdaptWhite, "Check to adapt the white-point based on the color statistics of the active circle" +
				".");
			this.checkAdaptWhite.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.checkAdaptWhite.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.checkAdaptWhite.CheckedChanged += new System.EventHandler(this.checkAdaptWhite_CheckedChanged);
			// 
			// labelCalculus
			// 
			this.labelCalculus.Location = new System.Drawing.Point(4, 280);
			this.labelCalculus.Name = "labelCalculus";
			this.labelCalculus.Size = new System.Drawing.Size(88, 20);
			this.labelCalculus.TabIndex = 11;
			this.labelCalculus.Text = "Calculus order:";
			this.labelCalculus.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.labelCalculus, @"The order of derivation (negative) or integration (positive).  A zero-value means that no integration or derivation is performed.  For example, a value of 1.0 gives the first order integral and a value of -1.0 gives the first order derivative.  A value of -2.0 would give the second order derivative.");
			this.labelCalculus.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.labelCalculus.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// checkBidirectional
			// 
			this.checkBidirectional.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.checkBidirectional.Checked = true;
			this.checkBidirectional.CheckState = System.Windows.Forms.CheckState.Checked;
			this.checkBidirectional.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.checkBidirectional.Location = new System.Drawing.Point(32, 64);
			this.checkBidirectional.Name = "checkBidirectional";
			this.checkBidirectional.Size = new System.Drawing.Size(88, 18);
			this.checkBidirectional.TabIndex = 11;
			this.checkBidirectional.Text = "Bidirectional";
			this.checkBidirectional.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.checkBidirectional, "Each value in the output is raised to the exponent of 1/gamma.  If this is checke" +
				"d, a good gamma value is automatically calculated for you.");
			this.checkBidirectional.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.checkBidirectional.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(104, 16);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(20, 23);
			this.label6.TabIndex = 12;
			this.label6.Text = "pi";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.toolTip1.SetToolTip(this.label6, "The mean of orientation tuning (in radians).");
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(104, 40);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(20, 23);
			this.label7.TabIndex = 13;
			this.label7.Text = "pi";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.toolTip1.SetToolTip(this.label7, "The mean of orientation tuning (in radians).");
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(4, 370);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(86, 22);
			this.label9.TabIndex = 12;
			this.label9.Text = "Tween Frames:";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label9, "Number of interpolated frames after this control frame.");
			// 
			// label10
			// 
			this.label10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.label10.Location = new System.Drawing.Point(210, 394);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(132, 20);
			this.label10.TabIndex = 14;
			this.label10.Text = "Movie Filename Prefix:";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label10, @"The order of derivation (negative) or integration (positive).  A zero-value means that no integration or derivation is performed.  For example, a value of 1.0 gives the first order integral and a value of -1.0 gives the first order derivative.  A value of -2.0 would give the second order derivative.");
			// 
			// textNtween
			// 
			this.textNtween.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textNtween.Location = new System.Drawing.Point(92, 370);
			this.textNtween.Name = "textNtween";
			this.textNtween.Size = new System.Drawing.Size(36, 20);
			this.textNtween.TabIndex = 5;
			this.textNtween.Text = "10";
			this.textNtween.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textNtween, "Number of interpolated frames after this control frame.");
			// 
			// textGamma
			// 
			this.textGamma.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textGamma.Location = new System.Drawing.Point(92, 324);
			this.textGamma.Name = "textGamma";
			this.textGamma.Size = new System.Drawing.Size(36, 20);
			this.textGamma.TabIndex = 9;
			this.textGamma.Text = "1.0";
			this.textGamma.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textGamma, "The degree to which pixel values are inflated for display purposes.  A number gre" +
				"ater than 1 inflates pixels, less than 1 deflates them.  Each value in the outpu" +
				"t is raised to the exponent of 1/gamma.");
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(2, 324);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(90, 20);
			this.label11.TabIndex = 15;
			this.label11.Text = "Gamma";
			this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label11, "The degree to which pixel values are inflated for display purposes.  A number gre" +
				"ater than 1 inflates pixels, less than 1 deflates them.  Each value in the outpu" +
				"t is raised to the exponent of 1/gamma.");
			// 
			// textWhiteFac
			// 
			this.textWhiteFac.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textWhiteFac.Location = new System.Drawing.Point(92, 348);
			this.textWhiteFac.Name = "textWhiteFac";
			this.textWhiteFac.Size = new System.Drawing.Size(36, 20);
			this.textWhiteFac.TabIndex = 16;
			this.textWhiteFac.Text = "1";
			this.textWhiteFac.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textWhiteFac, "A value of 1 means full adaptation, 0 means no adaptation, and intermediate value" +
				"s weight adaptation.");
			// 
			// textMovieWidth
			// 
			this.textMovieWidth.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textMovieWidth.Location = new System.Drawing.Point(488, 332);
			this.textMovieWidth.Name = "textMovieWidth";
			this.textMovieWidth.Size = new System.Drawing.Size(64, 20);
			this.textMovieWidth.TabIndex = 18;
			this.textMovieWidth.Text = "800";
			this.textMovieWidth.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textMovieWidth, "The center frequency is a positive number that determines the center of frequency" +
				" tuning for the log-gabor function.");
			// 
			// textMovieHeight
			// 
			this.textMovieHeight.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textMovieHeight.Location = new System.Drawing.Point(488, 354);
			this.textMovieHeight.Name = "textMovieHeight";
			this.textMovieHeight.Size = new System.Drawing.Size(64, 20);
			this.textMovieHeight.TabIndex = 19;
			this.textMovieHeight.Text = "600";
			this.textMovieHeight.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.toolTip1.SetToolTip(this.textMovieHeight, "The center frequency is a positive number that determines the center of frequency" +
				" tuning for the log-gabor function.");
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(448, 330);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(40, 23);
			this.label12.TabIndex = 20;
			this.label12.Text = "Width";
			this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label12, "The standard deviation of orientation tuning (in radians).");
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(448, 350);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(40, 23);
			this.label13.TabIndex = 21;
			this.label13.Text = "Height";
			this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.toolTip1.SetToolTip(this.label13, "The standard deviation of orientation tuning (in radians).");
			// 
			// checkBox1
			// 
			this.checkBox1.Checked = true;
			this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
			this.checkBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBox1.Location = new System.Drawing.Point(322, 330);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(124, 18);
			this.checkBox1.TabIndex = 22;
			this.checkBox1.Text = "Render All Channels";
			this.toolTip1.SetToolTip(this.checkBox1, "Check to display the output in the Object Parser window.");
			// 
			// groupOrientation
			// 
			this.groupOrientation.Controls.Add(this.label7);
			this.groupOrientation.Controls.Add(this.label6);
			this.groupOrientation.Controls.Add(this.checkBidirectional);
			this.groupOrientation.Controls.Add(this.textCenterOrientation);
			this.groupOrientation.Controls.Add(this.label4);
			this.groupOrientation.Controls.Add(this.label5);
			this.groupOrientation.Controls.Add(this.textWidthOrientation);
			this.groupOrientation.Enabled = false;
			this.groupOrientation.Location = new System.Drawing.Point(2, 196);
			this.groupOrientation.Name = "groupOrientation";
			this.groupOrientation.Size = new System.Drawing.Size(128, 84);
			this.groupOrientation.TabIndex = 6;
			this.groupOrientation.TabStop = false;
			this.groupOrientation.Text = "Orientation";
			this.groupOrientation.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.groupOrientation.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// butRefresh
			// 
			this.butRefresh.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.butRefresh.Location = new System.Drawing.Point(2, 394);
			this.butRefresh.Name = "butRefresh";
			this.butRefresh.Size = new System.Drawing.Size(126, 20);
			this.butRefresh.TabIndex = 7;
			this.butRefresh.Text = "Refresh";
			this.butRefresh.Click += new System.EventHandler(this.butRefresh_Click);
			this.butRefresh.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.butRefresh.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			// 
			// textCalculus
			// 
			this.textCalculus.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textCalculus.Location = new System.Drawing.Point(94, 282);
			this.textCalculus.Name = "textCalculus";
			this.textCalculus.Size = new System.Drawing.Size(34, 20);
			this.textCalculus.TabIndex = 12;
			this.textCalculus.Text = "0";
			this.textCalculus.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.mSaveAs,
																					  this.menuItem2});
			this.menuItem1.Text = "File";
			// 
			// mSaveAs
			// 
			this.mSaveAs.Index = 0;
			this.mSaveAs.Text = "Save Frame As...";
			this.mSaveAs.Click += new System.EventHandler(this.mSaveAs_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "-";
			// 
			// panelLeft
			// 
			this.panelLeft.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panelLeft.Controls.Add(this.textWhiteFac);
			this.panelLeft.Controls.Add(this.checkFreq);
			this.panelLeft.Controls.Add(this.groupFreq);
			this.panelLeft.Controls.Add(this.textGamma);
			this.panelLeft.Controls.Add(this.butRefresh);
			this.panelLeft.Controls.Add(this.checkDisplay);
			this.panelLeft.Controls.Add(this.label1);
			this.panelLeft.Controls.Add(this.listColorDim);
			this.panelLeft.Controls.Add(this.textCalculus);
			this.panelLeft.Controls.Add(this.groupOrientation);
			this.panelLeft.Controls.Add(this.checkOrientation);
			this.panelLeft.Controls.Add(this.checkAdaptWhite);
			this.panelLeft.Controls.Add(this.labelCalculus);
			this.panelLeft.Controls.Add(this.label9);
			this.panelLeft.Controls.Add(this.textNtween);
			this.panelLeft.Controls.Add(this.label11);
			this.panelLeft.Location = new System.Drawing.Point(2, 2);
			this.panelLeft.Name = "panelLeft";
			this.panelLeft.Size = new System.Drawing.Size(132, 418);
			this.panelLeft.TabIndex = 13;
			// 
			// panelMovie
			// 
			this.panelMovie.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.panelMovie.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panelMovie.Controls.Add(this.checkBox1);
			this.panelMovie.Controls.Add(this.label13);
			this.panelMovie.Controls.Add(this.label12);
			this.panelMovie.Controls.Add(this.textMovieHeight);
			this.panelMovie.Controls.Add(this.textMovieWidth);
			this.panelMovie.Controls.Add(this.butMoveUp);
			this.panelMovie.Controls.Add(this.bMovieDirectory);
			this.panelMovie.Controls.Add(this.label10);
			this.panelMovie.Controls.Add(this.textMoviename);
			this.panelMovie.Controls.Add(this.bRemove);
			this.panelMovie.Controls.Add(this.bAdd);
			this.panelMovie.Controls.Add(this.bRender);
			this.panelMovie.Controls.Add(this.clbFrames);
			this.panelMovie.Controls.Add(this.label8);
			this.panelMovie.Controls.Add(this.butMoveDown);
			this.panelMovie.Location = new System.Drawing.Point(136, 2);
			this.panelMovie.Name = "panelMovie";
			this.panelMovie.Size = new System.Drawing.Size(556, 418);
			this.panelMovie.TabIndex = 14;
			// 
			// butMoveUp
			// 
			this.butMoveUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.butMoveUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.butMoveUp.Location = new System.Drawing.Point(382, 2);
			this.butMoveUp.Name = "butMoveUp";
			this.butMoveUp.Size = new System.Drawing.Size(84, 22);
			this.butMoveUp.TabIndex = 16;
			this.butMoveUp.Text = "Move Up";
			// 
			// bMovieDirectory
			// 
			this.bMovieDirectory.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.bMovieDirectory.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.bMovieDirectory.Location = new System.Drawing.Point(16, 392);
			this.bMovieDirectory.Name = "bMovieDirectory";
			this.bMovieDirectory.Size = new System.Drawing.Size(190, 22);
			this.bMovieDirectory.TabIndex = 15;
			this.bMovieDirectory.Text = "Change Movie File Directory...";
			this.bMovieDirectory.Click += new System.EventHandler(this.bMovieDirectory_Click);
			// 
			// textMoviename
			// 
			this.textMoviename.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.textMoviename.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textMoviename.Location = new System.Drawing.Point(346, 394);
			this.textMoviename.Name = "textMoviename";
			this.textMoviename.Size = new System.Drawing.Size(102, 20);
			this.textMoviename.TabIndex = 13;
			this.textMoviename.Text = "mov";
			// 
			// bRemove
			// 
			this.bRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.bRemove.Location = new System.Drawing.Point(174, 2);
			this.bRemove.Name = "bRemove";
			this.bRemove.Size = new System.Drawing.Size(58, 22);
			this.bRemove.TabIndex = 4;
			this.bRemove.Text = "Remove";
			this.bRemove.Click += new System.EventHandler(this.bRemove_Click);
			// 
			// bAdd
			// 
			this.bAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.bAdd.Location = new System.Drawing.Point(114, 2);
			this.bAdd.Name = "bAdd";
			this.bAdd.Size = new System.Drawing.Size(58, 22);
			this.bAdd.TabIndex = 3;
			this.bAdd.Text = "Add";
			this.bAdd.Click += new System.EventHandler(this.bAdd_Click);
			// 
			// bRender
			// 
			this.bRender.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.bRender.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.bRender.Location = new System.Drawing.Point(450, 394);
			this.bRender.Name = "bRender";
			this.bRender.Size = new System.Drawing.Size(102, 20);
			this.bRender.TabIndex = 2;
			this.bRender.Text = "Render Frames";
			this.bRender.Click += new System.EventHandler(this.bRender_Click);
			// 
			// clbFrames
			// 
			this.clbFrames.AllowDrop = true;
			this.clbFrames.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.clbFrames.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.clbFrames.Location = new System.Drawing.Point(2, 26);
			this.clbFrames.Name = "clbFrames";
			this.clbFrames.Size = new System.Drawing.Size(550, 302);
			this.clbFrames.TabIndex = 1;
			this.clbFrames.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.clbFrames.SelectedIndexChanged += new System.EventHandler(this.clbFrames_SelectedIndexChanged);
			this.clbFrames.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(2, 4);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(106, 18);
			this.label8.TabIndex = 0;
			this.label8.Text = "Control Frames";
			this.label8.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			// 
			// butMoveDown
			// 
			this.butMoveDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.butMoveDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.butMoveDown.Location = new System.Drawing.Point(468, 2);
			this.butMoveDown.Name = "butMoveDown";
			this.butMoveDown.Size = new System.Drawing.Size(84, 22);
			this.butMoveDown.TabIndex = 17;
			this.butMoveDown.Text = "Move Down";
			// 
			// FormLogGabor
			// 
			this.AllowDrop = true;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(694, 423);
			this.Controls.Add(this.panelMovie);
			this.Controls.Add(this.panelLeft);
			this.Menu = this.mainMenu1;
			this.Name = "FormLogGabor";
			this.Text = "Log Gabor Filter";
			this.TopMost = true;
			this.Load += new System.EventHandler(this.FormLogGabor_Load);
			this.DragDrop += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragDrop);
			this.Closed += new System.EventHandler(this.FormLogGabor_Closed);
			this.DragEnter += new System.Windows.Forms.DragEventHandler(this.FormLogGabor_DragEnter);
			this.groupFreq.ResumeLayout(false);
			this.groupOrientation.ResumeLayout(false);
			this.panelLeft.ResumeLayout(false);
			this.panelMovie.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		public float[,,] PixelValues=null;
		
		public Complex2f ImgSpatial;
		public Complex2f ImgFourier;
		public Complex2f FilterFourier;
		public Complex2f FilterSpatial;
		public FftPlan2 PlanForwards=null;
		public FftPlan2 PlanBackwards=null;

		public LogGaborParams CurrentParams = null;
		public LogGaborParams LastRefreshedParams = null;

		public Bitmap DiplayResult=null;
		public string movieSavePath=null;

		public FilterSet Lum=null;
		public FilterSet AllColors=null;
		public FilterSet CurrentSet=null;

		public FormParse Parser;

		public static NumericalRecipes.Nr NrStaticResources = new NumericalRecipes.Nr();
	
		public FormLogGabor(FormParse Parser)
		{
			this.Parser = Parser;
			if(Parser.CorePixels==null)
				this.Parser.LoadCorePixels();
			InitializeComponent();
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		private void FormLogGabor_Load(object sender, System.EventArgs e)
		{
			listColorDim.DisplayMember = "Text";
			PopulateListBox(this.listColorDim, typeof(BmgNet.ColorDim));
			listColorDim.SelectedIndex = 0;
			CurrentParams = this.ExtractParams();
			clbFrames.Items.Add(CurrentParams);
			clbFrames.SelectedIndex = 0;
			clbFrames.SetItemChecked(0, true);
			clbFrames.SetSelected(0, true);
			this.textWhiteFac.Enabled = this.checkAdaptWhite.Checked;
			this.Width=panelLeft.Width+20;
		}
		private void FormLogGabor_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
		{
			if( LogGaborParamsDragFile(e.Data) )
				e.Effect = DragDropEffects.Copy;
		}
		private void FormLogGabor_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
		{
			if( LogGaborParamsDragFile(e.Data) )
			{
				e.Effect = DragDropEffects.Copy;
				string[] dirs = (string[])(e.Data.GetData("FileDrop"));
				string filepath = dirs[0];
				LogGaborArray arr =  LogGaborArray.DeserializeBinary(filepath);
				string lastSaveDir = "";
				int i = filepath.Length-2;
				while(i>0)
				{
					if(filepath[i]=='/' || filepath[i]=='\\')
					{
						lastSaveDir = filepath.Substring(0, i);
						break;;
					}
					i--;
				}
				if(i==0)
					lastSaveDir = null;
				for(i=0; i<arr.Count; i++)
				{
					clbFrames.Items.Add(arr[i]);
				}
			}
		}
		private static bool LogGaborParamsDragFile(IDataObject data)
		{
			if(data.GetDataPresent("FileNameW"))
			{
				object o = data.GetData("FileDrop");
				string[] dirs = (string[]) o;
				
				if(dirs.Length > 0)
					if(dirs[0].EndsWith(".LogGaborParams"))
						if(File.Exists(dirs[0]))
							return true;
			}
			return false;
		}
		private void mSaveAs_Click(object sender, System.EventArgs e)
		{
			LogGaborArray arr = ExtractControlFrames();
			if(arr != null)
			{
				string fname = "";
				if(CurrentParams.lastSaveDir!=null && CurrentParams.lastSaveDir.Length>0)
					Sfd.InitialDirectory = CurrentParams.lastSaveDir;
				Sfd.FileName = fname = CurrentParams.ToString() + ".LogGaborParams";
				Sfd.AddExtension = true;
				Sfd.Filter = "Log Gabor Parameters|*.LogGaborParams";
				Sfd.FilterIndex=0;
				Sfd.Title = "Save Log Gabor Parameters";
				if(DialogResult.OK == Sfd.ShowDialog())
				{
					string filepath = Sfd.FileName;
					arr.SerializeBinary(filepath);
				}
			}
		}
		public static void PopulateListBox(ListBox lb, Type enumType)
		{
			string[] names = Enum.GetNames(enumType);
			Array enumVals = Enum.GetValues(enumType);
			ListViewItem lvi;
			for(int i=0; i<names.Length; i++)
			{
				lvi = new ListViewItem();
				lvi.Text = names[i];
				lvi.Tag = enumVals.GetValue(i);
				lb.Items.Add(lvi);
			}
		}
		private void checkDisplay_CheckedChanged(object sender, System.EventArgs e)
		{
			if(checkDisplay.Checked)
			{
				if(CurrentSet!=null && CurrentSet.Result!=null)
				{
					Parser.Bmp = CurrentSet.Result;
					Parser.Pb.Invalidate();
				}
			}
			else
			{
				Parser.Bmp = Parser.DisplayBmp;
				Parser.Pb.Invalidate();
			}
		}
		public void OnNewProjectLoaded()
		{
			CurrentParams = null;
			Parser.LoadCorePixels();
			Lum = AllColors = CurrentSet = null;
		}
		/// <summary>
		/// Insures that memory is allocated and pixels updated for all transforms.
		/// </summary>
		/// <param name="p"></param>
		public FilterSet AllocFilterSet(LogGaborParams p)
		{
			FilterSet output=null;

			float fac = this.Parser.Opd.PixelFactor;
			if(fac==0.0f || float.IsNaN(fac) || float.IsInfinity(fac))
				fac = 1000.0f;

			if(p.Channel==ColorDim.LogLmsLum)
			{
				output = Lum;
				if(Lum==null)
					Lum = output = new FilterSet(p, this.Parser.CorePixels, fac, this.Parser.Opd);
			}
			else
			{
				output = AllColors;
				if(AllColors==null)
					AllColors = output = new FilterSet(p, this.Parser.CorePixels, fac, this.Parser.Opd);
			}
			return output;
		}
		private void butRefresh_Click(object sender, System.EventArgs e)
		{
			Cursor oldCursor = Cursor.Current;
			Cursor.Current = Cursors.WaitCursor;

			LogGaborParams p = ExtractParams();
			if(p!=null)
			{
				CurrentParams = p;
				CurrentSet = AllocFilterSet(p);
				CurrentSet.Go(CurrentParams);
				if(this.checkDisplay.Checked)
				{
					Parser.Bmp = CurrentSet.Result;
					Parser.Pb.Invalidate();
				}
				LastRefreshedParams = p;
			}

			this.clbFrames.Items[this.clbFrames.SelectedIndex] = CurrentParams;

			System.GC.Collect();
			Cursor.Current = oldCursor;
		}
		private void checkFreq_CheckedChanged(object sender, System.EventArgs e)
		{
			this.groupFreq.Enabled = this.checkFreq.Checked;
		}
		private void checkOrientation_CheckedChanged(object sender, System.EventArgs e)
		{
			this.groupOrientation.Enabled = this.checkOrientation.Checked;
		}
		private void FormLogGabor_Closed(object sender, System.EventArgs e)
		{
			if( Parser.Bmp != Parser.DisplayBmp )
			{
				Parser.Bmp = Parser.DisplayBmp;
				Parser.Pb.Invalidate();
			}
		}
		private void clbFrames_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(clbFrames.SelectedIndex>=0)
			{
				SetParams( (LogGaborParams)clbFrames.SelectedItem );
			}
		}
		private void bAdd_Click(object sender, System.EventArgs e)
		{
			CurrentParams = ExtractParams();
			clbFrames.Items.Add(CurrentParams);
			clbFrames.SelectedIndex = clbFrames.Items.Count-1;
			clbFrames.SetItemChecked(clbFrames.SelectedIndex, true);
		}
		private void bRemove_Click(object sender, System.EventArgs e)
		{
			if(clbFrames.Items.Count>1)
			{
				int ind = clbFrames.SelectedIndex;
				clbFrames.Items.RemoveAt(ind);
				if(ind>0)
					clbFrames.SelectedIndex = ind-1;
				else
					clbFrames.SelectedIndex = 0;
				SetParams( (LogGaborParams)clbFrames.SelectedItem );
			}
		}		
		public LogGaborParams ExtractParams()
		{
			LogGaborParams output = new LogGaborParams();
			output.Channel = (BmgNet.ColorDim)((ListViewItem)listColorDim.SelectedItem).Tag;
			output.DisplayInObjectParser = this.checkDisplay.Checked;
			output.ConstrainFrequency = this.checkFreq.Checked;
			output.ConstrainOrientation = this.checkOrientation.Checked;
			output.Bidirectional = this.checkBidirectional.Checked;
			output.AdaptWhite=this.checkAdaptWhite.Checked;
			output.WhiteningCircle = this.Parser.Opd.ActiveCircle;
			if(output.WhiteningCircle!=null)
				output.WhiteningCircle = (Circle)output.WhiteningCircle.Clone();
			try
			{
				output.AdaptWhiteFac = Convert.ToDouble(this.textWhiteFac.Text);
			}
			catch{ return null; }
			try
			{
				output.Gamma = Convert.ToDouble(this.textGamma.Text);
			}
			catch{ return null; }
			try
			{
				output.CenterFrequency = Convert.ToDouble(this.textCenterFreq.Text);
			}
			catch{ return null; }
			try
			{
				output.WidthFrequency = Convert.ToDouble(this.textWidthFreq.Text);
			}
			catch{ return null; }
			try
			{
				output.CenterOrientation = Math.PI*Convert.ToDouble(this.textCenterOrientation.Text);
			}
			catch{ return null; }
			try
			{
				output.WidthOrientation = Math.PI*Convert.ToDouble(this.textWidthOrientation.Text);
			}
			catch{ return null; }
			try
			{
				output.Calculus = Convert.ToDouble(this.textCalculus.Text);
			}
			catch{ return null; }
			try
			{
				output.NtweenAfter = Convert.ToInt32(this.textNtween.Text);
				if(output.NtweenAfter<0)
				{
					output.NtweenAfter = 0;
					this.textNtween.Text = output.NtweenAfter.ToString();
				}
			}
			catch{	return null;}

			return output;
		}
		public void SetParams(LogGaborParams p)
		{
			if(p==null)
				return;
			for(int i=0; i<listColorDim.Items.Count; i++)
			{
				if((BmgNet.ColorDim)((ListViewItem)listColorDim.Items[i]).Tag==p.Channel)
					listColorDim.SelectedIndex = i;
			}
			this.checkDisplay.Checked=p.DisplayInObjectParser;
			this.checkFreq.Checked=this.groupFreq.Enabled=p.ConstrainFrequency;
			this.checkOrientation.Checked=this.groupOrientation.Enabled=p.ConstrainOrientation;
			this.checkBidirectional.Checked=p.Bidirectional;
			this.checkAdaptWhite.Checked = p.AdaptWhite;
			this.textWhiteFac.Text = p.AdaptWhiteFac.ToString();
			this.textGamma.Text=p.Gamma.ToString();
			this.textCenterFreq.Text=p.CenterFrequency.ToString();
			this.textWidthFreq.Text=p.WidthFrequency.ToString();
			this.textCenterOrientation.Text=(Math.Round(p.CenterOrientation/Math.PI,3)).ToString();
			this.textWidthOrientation.Text=(Math.Round(p.WidthOrientation/Math.PI,3)).ToString();
			this.textCalculus.Text=p.Calculus.ToString();
			this.textNtween.Text = p.NtweenAfter.ToString();
			CurrentParams = p;
		}
		public LogGaborArray ExtractControlFrames()
		{
			LogGaborArray output = new LogGaborArray();
			for(int i=0; i<clbFrames.Items.Count; i++)
				output.Add((LogGaborParams)clbFrames.Items[i]);
			return output;
		}
		public LogGaborArray ExtractAllFrames()
		{
			LogGaborArray controls = ExtractControlFrames();
			if(controls.Count<=1)
				return controls;

			LogGaborArray output = new LogGaborArray();
			int i;
			for(i=1; i<controls.Count; i++)
				output.AppendFrames(controls[i-1], controls[i]);
			output.Add(controls[controls.Count-1]);
			return output;
		}
		private void bMovieDirectory_Click(object sender, System.EventArgs e)
		{
			if(movieSavePath!=null)
				Dsd.SelectedPath = movieSavePath;
			if(Dsd.ShowDialog()==DialogResult.OK)
				movieSavePath = Dsd.SelectedPath;
		}
		private void bRender_Click(object sender, System.EventArgs e)
		{
			string mov = this.textMoviename.Text;
			string filename;
			LogGaborArray frames = ExtractAllFrames();
			FilterSet fset = new FilterSet(frames[0], Parser.CorePixels, Parser.Opd.PixelFactor, Parser.Opd);

			bool proceed = true;
			int width=0, height=0;
			try
			{
				width = Convert.ToInt32(this.textMovieWidth.Text);
				height = Convert.ToInt32(this.textMovieHeight.Text);
			}
			catch
			{
				proceed = false;
			}

			if(proceed && width>0 && height>0)
			{
				Bitmap bmpOut = new Bitmap(width, height);
				Graphics gOut = Graphics.FromImage(bmpOut);
				Rectangle destRect = new Rectangle(0,0,width,height);
				Rectangle sourceRect = new Rectangle(0,0,Parser.DisplayBmp.Width,Parser.DisplayBmp.Height);

				Cursor oldCursor = Cursor.Current;
				Cursor.Current = Cursors.WaitCursor;

				filename = movieSavePath + '\\' + mov + Util.PaddedIntegerString(0u,  4u) + ".jpg";
				gOut.DrawImage(Parser.DisplayBmp, destRect, sourceRect, GraphicsUnit.Pixel);
				bmpOut.Save(filename, ImageFormat.Jpeg);

				for(int i=0; i<frames.Count;  i++)
				{
					filename = movieSavePath + '\\' + mov + Util.PaddedIntegerString((uint)(i+1),  4u) + ".jpg";
					fset.Go(frames[i]);
					this.DiplayResult = fset.Result;
					Parser.Bmp = this.DiplayResult;
					Parser.Pb.Invalidate();
					gOut.DrawImage(this.DiplayResult, destRect, sourceRect, GraphicsUnit.Pixel);
					bmpOut.Save(filename, ImageFormat.Jpeg);
				}

				Cursor.Current = oldCursor;
			}
		}
		private void checkAdaptWhite_CheckedChanged(object sender, System.EventArgs e)
		{
			this.textWhiteFac.Enabled = checkAdaptWhite.Checked;
		}
	}
}
